// pages/admin/apply/apply.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    applications: [
      {
        id: 1,
        applicantName: "张三",
        userNumber: "20201234",
        phone: "12345678901",
        classroomType: "多媒体教室",
        timeSlots: ["14:00-15:00", "15:00-16:00"],
        reason: "用于社团活动",
        status: "pending"
      },
      {
        id: 2,
        applicantName: "李四",
        userNumber: "20205678",
        phone: "19876543210",
        classroomType: "普通教室",
        timeSlots: ["16:00-17:00"],
        reason: "用于小组讨论",
        status: "pending"
      }
    ],
    showDetailModal: false,
    selectedApplication: null
  },

   // 显示申请详情
   showDetails(e) {
    const id = e.currentTarget.dataset.id;
    const application = this.data.applications.find(app => app.id === id);
    this.setData({
      showDetailModal: true,
      selectedApplication: application
    });
  },

  // 隐藏申请详情
  hideDetails() {
    this.setData({ showDetailModal: false });
  },

  // 批准申请
  approveApplication() {
    const { selectedApplication } = this.data;
    this.updateApplicationStatus(selectedApplication.id, "approved");
    this.hideDetails();
  },

  // 拒绝申请
  rejectApplication() {
    const { selectedApplication } = this.data;
    this.updateApplicationStatus(selectedApplication.id, "rejected");
    wx.navigateTo({
      url: '/pages/admin/refuse/refuse',
    })
    this.hideDetails();
  },

  // 更新申请状态
  updateApplicationStatus(id, status) {
    const applications = this.data.applications.map(app => {
      if (app.id === id) {
        app.status = status;
      }
      return app;
    });
    this.setData({ applications });
    wx.showToast({
      title: status === "approved" ? "已批准" : "已拒绝",
      icon: "success",
      duration: 2000
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})